package com.zzptc.myapp1127;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.DialogTitle;

import android.os.Bundle;
import android.util.Log;

import com.zzptc.myapp1127.Service.QichepinpaiService;
import com.zzptc.myapp1127.entity.Qichepinpai;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getQichepinpaiInfo();

    }

    private void getQichepinpaiInfo() {
        //创建Retrofit对象
        Retrofit r=new Retrofit.Builder()
                .baseUrl("http://apis.juhe.cn/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        //创建接口对象
        QichepinpaiService qichepinpaiService=r.create(QichepinpaiService.class);

        //调用接口对象中的定义方法
        Map<String,String>map=new HashMap<>();
        map.put("key","79729168b7661c89f1f4e56936121f31");
        map.put("first_letter","D");
        Call<Qichepinpai>allPinpai=qichepinpaiService.getAllPinpai(map);

        //Call<Qichepinpai>call=qichepinpaiService.getAllPinpai("79729168b7661c89f1f4e56936121f31","c");
        //调用call接口中的异步方法
        allPinpai.enqueue(new Callback<Qichepinpai>() {
           @Override
           public void onResponse(Call<Qichepinpai> call, Response<Qichepinpai> response) {
               Qichepinpai qichepinpai=response.body();
              Log.d(TAG,"onResponse"+qichepinpai.getResult().size());
            }

            @Override
            public void onFailure(Call<Qichepinpai> call, Throwable t) {
                Log.d(TAG, "onFailure: "+t.getMessage());

          }
        });
   }
}
